Lifetimes Hierarchy
-
Permanent Allocation :
-
Memory that is never freed until the end of the program. This memory is persistent during the program lifetime.
-
-
Transient Allocation :
-
Memory that has a cycle-based lifetime. This memory only persists for the βcycleβ and is freed at the end of this cycle. An example of a cycle could be a frame within a graphical program (e.g. a game) or an update loop.
-
-
Scratch/Temporary Allocation :
-
Short-lived, quick memory that you just want to allocate and forget about. A common case for this is when generating a string and outputting it to a log.
-
Types of Allocators
-
-
There's a lot of things there.
-
-
C#malloc .
Where to allocate
Algorithms for searching for free blocks
-
First Fit.
-
Next Fit.
-
Optimization from First Fit, but increases fragmentation, apparently.
-
-
Best Fit.
Coalescing ("Growing together, fusing")
-
When we have two free blocks next to each other, merge them together into one large block.
Strategies
-
On free: coalesce.
-
Coalesce only above and below, once on free.
-
This is preferred as it has a more predictable performance.
-
-
Coalesce once in a while.
-
This can take a little while, but removes the need to do it every operation.
-
-
Free List, Where to allocate a block, Coalescing - Chris Kanich .
-
Exploring a heap allocated memory with
gdb, showing free lists, etc - Chris Kanich .